<template>
	<view class="profit-wrap page-bg">
		<view class="recharge">
			<view class="title desc">请输入充值金额</view>
			<input class="value" type="text" v-model="payMoney" placeholder="￥0.00" placeholder-class="placeholder" />
		</view>

		<view class="pay-type">
			<view class="pay-type__item" @click="selectPayType(2)">
				<image class="pay-type__icon" src="../../static/common/icon_09.png" mode=""></image>
				<view class="pay-type__type">微信支付</view>
				<image v-if="currentPayType!==2" class="pay-type__select" src="../../static/common/icon_07.png" mode=""></image>
				<image v-else class="pay-type__select" src="../../static/common/icon_07_on.png" mode=""></image>
			</view>
			<!-- #ifndef H5 -->
			<view class="pay-type__item" @click="selectPayType(3)">
				<image class="pay-type__icon" src="../../static/common/icon_10.png" mode=""></image>
				<view class="pay-type__type">支付宝支付</view>
				<image v-if="currentPayType!==3" class="pay-type__select" src="../../static/common/icon_07.png" mode=""></image>
				<image v-else class="pay-type__select" src="../../static/common/icon_07_on.png" mode=""></image>
			</view>
			<!-- #endif -->
		</view>

		<view class="circular-submit" @click="onceRecharge">立即充值</view>
	</view>
</template>

<script>
	import common from '../../utils/common.js'
	import {
		api
	} from '../../utils/api.js'

	export default {
		data() {
			return {
				currentPayType: 2,
				payMoney: '', // 充值金额
			}
		},

		methods: {
			selectPayType(payType) {
				this.currentPayType = payType
			},
			// 立即充值
			onceRecharge() {
				let payType = this.currentPayType
				if (this.payMoney === 0) {
					payType = 0
				}
				if(this.payMoney <= 0) {
					this.$showToast('请输入充值金额~'); return
				}
				let obj = {
					orderType: 4, // 必选参数 	订单类型,升级团长：1,拼团:2,购物：3,充值：4
					payType, // 免费参与：0,钱包支付：1,微信支付:2,支付宝支付:3,全被抵扣(实际支付0):4, 正常情况下，0和4不需要前端传，由后台自行判断，传其他123即可
					amount: this.payMoney, // 充值金额（可选参数）
				}
				api.placeAnOrder(obj, (res) => {
					if (!res.payParams) {
						this.$showToast('支付参数错误, 请稍后重试~');
						return
					}
					let payTypeView = this.currentPayType === 2 ? '微信支付' : '支付宝支付'
						let temp = { amount: this.payMoney, payType: payTypeView }
						common.uniPay(JSON.parse(res.payParams), temp, () => {
						common.setStorage('reChargeInfo', temp)
						this.$link('/pages/mine/profitRechargeSuccess')
					})
				})
			}
		}
	}
</script>

<style scoped lang="less">
	@import url('../../app.less');

	.profit-wrap {
		padding: 20rpx 30rpx;
		box-sizing: border-box;
	}

	.recharge {
		background-color: @f;
		.br;
		.content-20;
		margin-bottom: 20rpx;

		.value {
			height: 80rpx;
			line-height: 80rpx;
			width: 100%;
		}
	}

	.pay-type {
		.br;
	}

	.circular-submit {
		margin-top: 50rpx;
	}
</style>
